package com.ambitor.grass.view;

import java.sql.Connection;
import java.sql.SQLException;

import com.ambitor.grass.sql.util.ConnectionUtils;

public class PageData {

	private Connection conn;

	public PageData() {
	}

	public Connection getConn(String jndi) throws SQLException {
		if (conn == null) {
			conn = ConnectionUtils.getConnection(jndi);
		}
		return conn;
	}

	public Connection getConn() throws SQLException {
		if (conn == null) {
			conn = ConnectionUtils.getConnection(getDefaultJNDIName());
		}
		return conn;
	}

	public void setConn(Connection conn) {
		this.conn = conn;
	}

	public void close() throws SQLException {
		conn.close();
	}

	private String getDefaultJNDIName() {
		return "java:/comp/env/jdbc/ambitor";
	}

}